<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ page import="java.util.*"%>
<%@ page
	import="cn.myapps.core.validate.repository.action.ValidateRepositoryHelper"%>
<ww:bean name="cn.myapps.core.dynaform.form.action.FormHelper" id="fh">
	<ww:param name="moduleid" value="#parameters.moduleid" />
</ww:bean>
<html>
<o:MultiLanguage>
	<HEAD>
	<META http-equiv=Content-Type content="text/html; charset=UTF-8">
	<META HTTP-EQUIV="pragma" CONTENT="no-cache">
	<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
	<META HTTP-EQUIV="expires" CONTENT="0">
	<link rel="stylesheet" href='<ww:url value="/resource/css/main.css" />'
		type="text/css">
	<script src='<ww:url value="/dwr/util.js"/>'></script>
	<script src='<ww:url value="/dwr/engine.js"/>'></script>
	<script src='<ww:url value="/dwr/interface/Sequence.js"/>'></script>
	<script src='<ww:url value="/script/prototype.js"/>'></script>
	<script src='<ww:url value="/dwr/interface/FormHelper.js"/>'></script>
	<script language=JavaScript src="../../dialog/sequence.js"></script>
	<script language=JavaScript src="../../dialog/dialog.js"></script>
	<script language=JavaScript src="../../dialog/script.js"></script>
	<script src="../../dialog/common/fck_dialog_common.js"
		type="text/javascript"></script>
	<link href="../../css/dialog.css" rel="stylesheet" type="text/css" />

	<SCRIPT language=JavaScript>
var dialog	= window.parent ;
var oEditor = dialog.InnerDialogLoaded() ;
// Gets the document DOM
var oDOM = oEditor.FCK.EditorDocument ;
var oActiveEl = dialog.Selection.GetSelectedElement() ;

// 选项卡点击事件
function cardClick(cardID){
	var obj;
	for (var i=1;i<7;i++){
		obj=document.all("card"+i);
		obj.style.backgroundColor="#3A6EA5";
		obj.style.color="#FFFFFF";
	}
	obj=document.all("card"+cardID);
	obj.style.backgroundColor="#FFFFFF";
	obj.style.color="#3A6EA5";

	for (var i=1;i<7;i++){
		obj=document.all("content"+i);
		obj.style.display="none";
	}
	obj=document.all("content"+cardID);
	obj.style.display="";
}

//初始值
function InitDocument(){
	var editMode;
	oEditor.FCKLanguageManager.TranslatePage(document) ;
	//ev_init('content.type','_onactionviewid','_onactionformid','_onactionflowid');
	addRelatedFieldOptions();
		if ( oActiveEl){
			if(oActiveEl.name!=null){
				temp.name.value = HTMLDencode(oActiveEl.name);
			}

			if(oActiveEl.refreshOnChanged!=null){
				temp.refreshOnChanged.checked = oActiveEl.refreshOnChanged == "true";
			}else{
				temp.refreshOnChanged.checked = false;
			}

			if(oActiveEl.calculateOnRefresh!=null){
				temp.calculateOnRefresh.checked = oActiveEl.calculateOnRefresh == "true";
			}else{
				temp.calculateOnRefresh.checked = false;
			}

			if(oActiveEl.limitByUser!=null){
				temp.limitByUser.checked = oActiveEl.limitByUser == "true";
			}else{
				temp.limitByUser.checked = false;
			}

			if(oActiveEl.relatedField!=null){
				temp.relatedField.value = HTMLDencode(oActiveEl.relatedField);
			}

			if(oActiveEl.departmentLevel!=null){
				temp.departmentLevel.value = HTMLDencode(oActiveEl.departmentLevel);
			}

			if(oActiveEl.valueScript!=null){
				temp.valueScript.value = HTMLDencode(oActiveEl.valueScript);
			}

			if(oActiveEl.validateRule!=null){
				temp.validateRule.value = HTMLDencode(oActiveEl.validateRule);
			}

			if(oActiveEl.hiddenScript!=null){
				temp.hiddenScript.value = HTMLDencode(oActiveEl.hiddenScript);
			}

			if(oActiveEl.hiddenValue!=null){
				temp.hiddenValue.value = HTMLDencode(oActiveEl.hiddenValue);
			}

			if(oActiveEl.hiddenPrintScript!=null){
				temp.hiddenPrintScript.value = HTMLDencode(oActiveEl.hiddenPrintScript);
			}

			if(oActiveEl.printHiddenValue!=null){
				temp.printHiddenValue.value = HTMLDencode(oActiveEl.printHiddenValue);
			}

			if(oActiveEl.filtercondition!=null){
				temp.filtercondition.value =HTMLDencode(oActiveEl.filtercondition);
			}
			//temp.editMode.value = HTMLDencode(oActiveEl.editMode);
			
			if(oActiveEl.readonlyScript!=null){
				temp.readonlyScript.value = HTMLDencode(oActiveEl.readonlyScript);
			}

			if(oActiveEl.mobile!=null){
				temp.mobile.checked = oActiveEl.mobile == "true";
			}else{
				temp.mobile.checked = false;
			}

			if(oActiveEl.authority!=null){
				temp.authority.checked = oActiveEl.authority == "true";
			}else{
				temp.authority.checked = false;
			}

			if(oActiveEl.defaultOptionType!=null){
				temp.defaultOptionType.value = oActiveEl.defaultOptionType;
			}

			if(oActiveEl.allowEmpty!=null){
				temp.allowEmpty.checked = oActiveEl.allowEmpty== "true";
			}else{
				temp.allowEmpty.checked = false;
			}

			if(oActiveEl.editMode!=null){
				editMode=HTMLDencode(oActiveEl.editMode);
			}

			if(oActiveEl.processDescription!=null){
			    var items=HTMLDencode(oActiveEl.processDescription);
			    parseRelStr(items);
			}

		    
			if(oActiveEl.textType==null){
				oActiveEl.textType='text';
			}
			temp.textType.value = HTMLDencode(oActiveEl.textType);

			if(oActiveEl.validateLibs!=null){
				var libstr=HTMLDencode(oActiveEl.validateLibs);
				var lib=libstr.split(';');
				var validateLibs=document.getElementsByName('validateLibs');
			    for(var i=0; i< lib.length; i++){
			       for(var j=0; j< validateLibs.length; j++){
		 			if(validateLibs[j].value==lib[i]){
		 				validateLibs[j].checked=true;
		 					}
		 				}
		 			}
			}
		}
		else
			oActiveEl = null ;
		dialog.SetOkButton( true ) ;
		dialog.SetAutoSize( true ) ;
		SelectField( 'name' ) ;
		initForm();
		modeChange(editMode);
		window.top.toThisHelpPage("application_module_form_info_advance_dept");
}

function Ok()
{
	if(!ev_check()){
		return false;
	}
	oEditor.FCKUndo.SaveUndoStep() ;
	var className="cn.myapps.core.dynaform.form.ejb.DepartmentField";
	var id=getFieldId();
	var editMode=document.getElementsByName("editMode");  
	var ed="";   
    for(var i=0;i<editMode.length;i++){
		  if(editMode[i].checked){
			   ed += editMode[i].value;
	      }
	    }	
	var validateLibs=document.getElementsByName('validateLibs');
	var libs='';
	for(var i=0; i< validateLibs.length; i++){
 		if(validateLibs[i].checked){
 			libs+=validateLibs[i].value+";";
 		}
 	}
 	libs=libs.substring(0,libs.length-1);
	oActiveEl = CreateNamedElement( oEditor, oActiveEl, 'SELECT', {
									classname: className,
									id: id,
									type:"text",
									name:HTMLEncode(temp.name.value),
									refreshOnChanged:HTMLEncode(temp.refreshOnChanged.checked+""),
									calculateOnRefresh:HTMLEncode(temp.calculateOnRefresh.checked+""),
									authority: HTMLEncode(temp.authority.checked+""),
									mobile: HTMLEncode(temp.mobile.checked+""),
									valueScript:HTMLEncode(temp.valueScript.value),
									validateRule:HTMLEncode(temp.validateRule.value),
									hiddenScript:HTMLEncode(temp.hiddenScript.value),
									hiddenValue:HTMLEncode(temp.hiddenValue.value),//////
									hiddenPrintScript:HTMLEncode(temp.hiddenPrintScript.value),
									printHiddenValue:HTMLEncode(temp.printHiddenValue.value),
									readonlyScript:HTMLEncode(temp.readonlyScript.value),
									
									fieldtype:"VALUE_TYPE_VARCHAR",
									textType:HTMLEncode(temp.textType.value),
									limitByUser:HTMLEncode(temp.limitByUser.checked+""),
									departmentLevel:HTMLEncode(temp.departmentLevel.value),
									relatedField:HTMLEncode(temp.relatedField.value),
									isDepartmentField:true,
									defaultOptionType:HTMLEncode(temp.defaultOptionType.value),
									allowEmpty:HTMLEncode(temp.allowEmpty.checked+""),
									
									filtercondition:HTMLEncode(temp.filtercondition.value),
									processDescription :HTMLEncode(createRelStr()),
								   	validateLibs:HTMLEncode(libs),
									editMode:HTMLEncode(ed)
									} 
								   ) ;	
	return true ;
}

//检查内容是否完成正确
function ev_check(){
   if(temp.name.value==''){
 	 alert("{*[page.name.notexist]*}");
	  return false;
   }
   return !checkStartChar(temp.name.value);
}

function checkStartChar(value){
	return IsDigit(value,"{*[page.name.startingit]*}");
}

function IsDigit(s,msg){
	var text = s.substring(0,1);
	var patrn=/^[0-9]{1}$/; 
	if(s=="action"){
	   	alert("action为关键字，不能作为字段名！");
	   	return true;
   	}else if (patrn.exec(text)){
		alert(msg);
		return true;
	}
	return false;
} 

function addRelatedFieldOptions(){
	var flds = oDOM.getElementsByTagName("SELECT");
	var oFieldNameSel = document.all('relatedField');
	addRelatedFieldOption(oFieldNameSel);
	for (var i=0; i<flds.length; i++) {
		if (flds[i].isDepartmentField) {
			if (oActiveEl == null || flds[i].id != oActiveEl.id) {
				addRelatedFieldOption(oFieldNameSel, flds[i]);
			}
		}
		//alert("id:" + flds[i].id + " | name:" + flds[i].name + " | className: " + flds[i].className + " | isDepartmentField: " + flds[i].isDepartmentField);
	}
}

function addRelatedFieldOption(oSel, oFld){
	var oOption = document.createElement("OPTION");
	if (oFld) {
		oOption.value = oFld.name;
		oOption.text = oFld.name;
	}
	oSel.options.add(oOption);
}

</script>

	</HEAD>

	<BODY bgcolor="menu" onload="InitDocument()">
	<form name="temp">
	<table border=0 cellpadding=3 cellspacing=0 width="520px">
		<tr>
			<td class="card" onclick="cardClick(1)" id="card1">{*[Basic]*}</td>
			<td width=2></td>
			<td class="card" onclick="cardClick(2)" id="card2">{*[Value_Script]*}</td>
			<td width=2></td>
			<td class="card" onclick="cardClick(3)" id="card3">{*[Validate_Script]*}</td>
			<td width=2></td>
			<td class="card" onclick="cardClick(4)" id="card4">{*[Hidden_Script]*}</td>
			<td width=2></td>
			<td class="card" onclick="cardClick(5)" id="card5">{*[Hidden_Print_Script]*}</td>
			<td width=2></td>
			<td class="card" onclick="cardClick(6)" id="card6">{*[ReadOnly_Script]*}</td>
		</tr>
		<tr>
			<td valign="middle" colspan="13" bgcolor="#ffffff" align="center"
				width="100%">

			<table border=1 cellpadding=3 cellspacing=0 class="content"
				width="100%" id="content1" width="520px">
				<tr>
					<td class="commFont commLabel">{*[Name]*}:</td>
					<td><input type=text name="name"
						onchange="checkStartChar(this.value);" /></td>
					<td class="commFont commLabel">{*[TextType]*}:</td>
					<td><select name="textType">
						<option value="text" selected>{*[Common]*}</option>
						<option value="readonly">{*[Readonly]*}</option>
						<option value="hidden">{*[Hidden]*}</option>
					</select></td>
				</tr>
				<tr>
					<td colspan="4" align="center"><input type=checkbox
						name="refreshOnChanged" value="true" />{*[Refresh]*}&nbsp; <input
						type=checkbox name="calculateOnRefresh" value="true" />{*[Recalculate]*}&nbsp;
					<input type=checkbox name="mobile" value="true" checked />{*[Mobile]*}&nbsp;
					<input type=checkbox name="authority" value="true" />{*[Authority]*}&nbsp;
					</td>
				</tr>
				<tr>
					<td class="commFont commLabel">{*[Department_Level]*}:</td>
					<td><ww:select theme="simple" name="departmentLevel"
						list="#{-1:'{*[All]*}',0:'0',1:'1',2:'2',3:'3',4:'4'}"
						label="{*[Department Level]*}" /></td>
					<td class="commFont commLabel">{*[Superior]*}{*[Department]*}:</td>
					<td><ww:select theme="simple" name="relatedField" list="{}"
						label="{*[Related Field]*}" /></td>
				</tr>
				<tr>
					<td class="commFont commLabel">{*[LimitByUser]*}:</td>
					<td><input type="checkbox" name="limitByUser" value="true" /></td>
					<td class="commFont commLabel">{*[DefaultOption]*}{*[Type]*}:</td>
					<td><ww:select theme="simple" name="defaultOptionType"
						list="#{16:'{*[FirstOption]*}',256:'{*[department.of.user]*}'}"
						label="{*[DefaultOption]*}{*[Type]*}" /></td>
				</tr>
				<tr>
					<td class="commFont commLabel">{*[EmptyOption]*}:</td>
					<td><input type="checkbox" name="allowEmpty" value="true" /></td>
					<td></td>
					<td></td>
				</tr>
			</table>

			<table border=1 cellpadding=3 cellspacing=0 class="content"
				id="content2" width="520px">
				<tr>
					<%@include file="../../dialog/commondialog.jsp"%>
				</tr>
				<table border=1 cellpadding=3 cellspacing=1 class="content"
					id="content3" width="520px">
					<tr>
						<td width="25%">
						<table>
							<%
								String applicationid = request.getParameter("application");
								ValidateRepositoryHelper vrhpler = new ValidateRepositoryHelper();
								Map map = vrhpler.get_validate(applicationid);
								for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
									Object id = (Object) iter.next();
									String name = (String) map.get(id);
							%><tr>
								<td><input type="checkbox" name="validateLibs"
									value="<%=(String)id %>" /><%=name%></td>
							</tr>
							<%
								}
							%>
						</table>
						</td>
						<td width="75%"><textarea name="validateRule"
							style="width: 95%" rows="10"></textarea>
							<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('validateRule','{*[Script]*}{*[Editor]*}','{*[Validate_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
							</td>
					</tr>
				</table>

				<table border=1 cellpadding=3 cellspacing=0 class="content"
					id="content4" width="520px">
					<tr>
						<td><textarea name="hiddenScript" style="width: 96%"
							rows="10"></textarea>
							<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('hiddenScript','{*[Script]*}{*[Editor]*}','{*[Hidden_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
						</td>
					</tr>
					<tr>
						<td>{*[hiddenValue]*}：<input id="hiddenValue" type="text" name="hiddenValue" /></td>
					</tr>
				</table>

				<table border=1 cellpadding=3 cellspacing=0 class="content"
					id="content5" width="520px">
					<tr>
						<td><textarea name="hiddenPrintScript" style="width: 96%"
							rows="10"></textarea>
							<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('hiddenPrintScript','{*[Script]*}{*[Editor]*}','{*[Hidden_Print_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
							</td>
					</tr>
					<tr>
						<td>{*[Print]*}{*[hiddenValue]*}：<input  type="text" name="printHiddenValue" /></td>
					</tr>
				</table>

				<table border=1 cellpadding=3 cellspacing=0 class="content"
					id="content6" width="520px">
					<tr>
						<td><textarea name="readonlyScript" style="width: 96%"
							rows="10"></textarea>
							<button style="border:0px;cursor: pointer;" onclick="openIscriptEditor('readonlyScript','{*[Script]*}{*[Editor]*}','{*[ReadOnly_Script]*}','name','{*[Save]*}{*[Success]*}');"><img alt="Open with IscriptEditor" src="<ww:url value='/resource/image/editor.png' />"/></button>
							</td>
					</tr>
				</table>

				</td>
				</tr>
			</table>
		</td>
		</tr>
	</table>
	</form>
	</BODY>
</o:MultiLanguage>
<script type="text/javascript" language="javascript" >
	cardClick(1);
</script>
</html>
